package com.cbgolf.oa.activity.closepark;

import android.content.Intent;
import android.os.Bundle;
import com.cbgolf.oa.R;
import com.cbgolf.oa.activity.BaseNewActivity;
import com.cbgolf.oa.contract.ICloseParkListContract;
import com.cbgolf.oa.entity.Beans;
import com.cbgolf.oa.event.Events;
import com.cbgolf.oa.manager.DataManager;
import com.cbgolf.oa.presenter.CloseParkListPresenterImpl;
import com.cbgolf.oa.util.ClassUtil;
import com.cbgolf.oa.util.EnumUtil;
import com.cbgolf.oa.views.CloseParkViewImp;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @author lq
 */
public class CloseParkListActivity extends BaseNewActivity implements
    ICloseParkListContract.Waiter {

  private ICloseParkListContract.Presenter presenter;
  private ICloseParkListContract.View view;

  @Override
  protected int getLayoutId() {
    return R.layout.a_recycler_list2;
  }

  @Override
  protected void init(Bundle savedInstanceState) {
    EventBus.getDefault().register(this);
    view = new CloseParkViewImp(this, this);
    presenter = new CloseParkListPresenterImpl();
    presenter.init(view);
    presenter.requestData();
  }

  @Override
  protected void onResume() {
    presenter.requestData();
    super.onResume();
  }


  @Override
  protected void onDestroy() {
    super.onDestroy();
    EventBus.getDefault().unregister(this);
  }

  @Subscribe(threadMode = ThreadMode.MAIN)
  public void requestOver(Events events) {
    if (null != view) {
      view.requestOver(events);
    }
  }

  @Override
  public String getActivityTitle() {
    return getString(R.string.close_park);
  }

  @Override
  public void back() {
    finish();
  }

  @Override
  public void addClosePark() {
    ClassUtil.startActivity(this, new Intent(this, CloseParkActivity.class)
        .putExtra(DataManager.KEY_TYPE, EnumUtil.CLOSE_PARK_ADD_NEW));
  }

  @Override
  public void loadMore() {
    presenter.requestData();
  }

  @Override
  public void refresh() {
    presenter.requestData();
  }

  @Override
  public void showDetails(Beans beans) {
    ClassUtil.startActivity(this, new Intent(this, CloseParkActivity.class)
        .putExtra(DataManager.KEY_TYPE, EnumUtil.CLOSE_PARK_SHOW_DETAILS)
        .putExtra(DataManager.KEY_DATA, beans));
  }
}
